import { hasToken } from '@/utils/storage'
import { Redirect, Route, RouteProps } from 'react-router-dom'

export default function PrivateRoute ({ children, ...res }: RouteProps) {
  // console.log('props',props)
  return (<Route {...res} render={() => {
    if (hasToken()) {
      return children
    } else {
      console.log('没有token，去login,传递给login参数：当前的页面地址是', res.location?.pathname)
      return <Redirect to={{
        pathname: '/login',
        state: {
          from: res.location?.pathname
        }
      }} ></Redirect>
    }
  }}></Route>)
}
